timedatectl
sudo hwclock --show --localtime # do not adjust to local timezone. (it's already localtime)
It will display what the current time is according to the hardware clock.
If this time matches whatever your watch says, then the hardware clock is set to local time.
If the output from hwclock is not local time, chances are it is set to UTC time.
systemd-timedated reads /etc/adjtime, and depending on the contents of the file, it sets the clock to either UTC or local time.
If /etc/adjtime isn't present at boot, systemd-timedated will assume that hardware clock is set to UTC.
When a os uses UTC it will consider CMOS time as a UTC then makes an adjustment to it.
when using localtime:
sudo timedatectl set-local-rtc true
cat /etc/adjtime # used by hwclock
sudo timedatectl set-local-rtc false # do not use localtime -> Set to UTC
cat /etc/adjtime
Network Time Protocol is a networking protocol for clock synchronization between computer systems
grep -i ntp /etc/systemd/timesyncd.conf
NTP=ir.pool.ntp.org
systemctl is-enabled systemd-timesyncd.service
sudo timedatectl set-ntp true
systemctl is-enabled systemd-timesyncd.service
timedatectl status | grep -i ntp
sudo dpkg-reconfigure tzdata
<img src="img/dpkg-rec-tzdata.png" /img>
cat /etc/timezone
file /etc/localtime
We will get back to these files for manual configuration.
timedatectl list-timezones | grep -i tehran
sudo timedatectl set-timezone Asia/Tehran
timedatectl status | grep zone
timedatectl status | grep zone # In DST
It comes handy when you want to know what time it is in other countries, or if you just wonder what timezones exist.
tzselect
<img src="img/tzselect.png" /img>
Here is that TZ value again, this time on standard output so that you can use the /usr/bin/tzselect command in shell scripts:
Asia/Tehran
tzselect 2> /dev/null
4
16
1
Asia/Tehran
export TZ=Europe/Germany
date
export TZ=Asia/Tehran
date
cat /etc/timezone
ll /etc/localtime
ls /usr/share/zoneinfo/
ls -l /usr/share/zoneinfo/Asia/Tehran
file /usr/share/zoneinfo/Iran
echo Asia/Tehran | sudo tee /etc/timezone
sudo ln -l /usr/share/zoneinfo/Asia/Tehran /etc/localtime
locale is a set of parameters that defines the user's language, region and any special variant preferences that the user wants to see in their user interface. Usually a locale identifier consists of at least a language identifier and a region identifier.
locale # out config
timedatectl | head -1
locale -a | grep -i fa # show all available locales
export LC_TIME=fa_IR.utf8
timedatectl | head -1
lets see what we got
grep '^[a-z]' /etc/locale.gen
lets see if we got any locale enabled for france:
localectl list-locales | grep -i fr # eq to locale -a
locale -a | grep -i fr
sudo nano /etc/locale.gen # uncomment # fr_FR.UTF-8 UTF-8
lets check the file again
grep -v '^#' /etc/locale.gen | grep -v '^$'
whatis locale-gen
sudo locale-gen
localectl list-locales | grep -i fr
locale -a | grep -i fr
export LANG=fr_FR.utf8
timedatectl | head -1
localectl set-locale LANG=fr_FR.utf8
Also like always we can use .profile or anything like that to export LANG or other related environment variables.
man 5 localtime
man localectl
man timedatectl
man locale
man tzselect
https://en.wikipedia.org/wiki/Locale_(computer_software)
http://linuxfromscratch.org/lfs/view/systemd/chapter07/clock.html
https://wiki.archlinux.org/index.php/Time
https://help.ubuntu.com/community/UbuntuTime
https://www.cl.cam.ac.uk/~mgk25/mswish/ut-rtc.html
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Configuring_the_Date_and_Time-hwclock.html
ipynb
format: https://github.com/ravexina/linux-notes. html
exports of project available at: https://ravexina.github.io/linux-notes.Linux Notes by Milad As (Ravexina) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.